package com.example.br;

import android.app.Activity;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;




public class MainActivity extends Activity {
    private static final String SMS_ACTION="android.provider.Telephony.SMS_RECEIVED";
    private SMSReceiver smsReceiver=null;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button register = findViewById(R.id.register);
        register.setOnClickListener(new RegisterListener());
        Button unregister = findViewById(R.id.unregister);
        unregister.setOnClickListener(new UnregisterListener());
    }

    class RegisterListener implements View.OnClickListener {

        @Override
        public void onClick(View v) {
            smsReceiver=new();//生成一个BroadcastReceiver对象
            IntentFilter intentFilter=new IntentFilter();//生成一个IntentFilter对象
            intentFilter.addAction(SMS_ACTION);//添加过滤
            MainActivity.this.registerReceiver(smsReceiver,intentFilter);

        }
    }
    class UnregisterListener implements View.OnClickListener{

        @Override
        public void onClick(View v) {
            MainActivity.this.unregisterReceiver(smsReceiver);
        }
    }
}
